package com.example.demo.mapper;

import com.example.demo.entity.Info;
import com.example.demo.entity.Report;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface InfoMapper {
    /*查询所有的用户信息*/
    /*在查询中，一律不可以使用*号作为查询字段,需要什么字段必须说明*/
    @Select("select * from Info")
    List<Info> findAllInfo();

    @Select("select * from Info where username=#{username}")
    List<Info> findAllInfo_Username(String username);

    @Select("select * from Info where id=#{id}")
    Info findAInfo(int id);

    @Delete("delete from Info where id=#{id}")
    int deleteAInfo(int id);

    @Insert("insert into info(title, username, phone, kind, picture, floor, type, area, elevator, decoration,  date, location, other, orientation, price, rights, joint, " +
            "lease, requirement, furniture) values (#{title}, #{username}, #{phone}, #{kind}, #{picture}, #{floor}, #{type}, #{area}, #{elevator}, #{decoration}, #{date}, " +
            "#{location}, #{other}, #{orientation}, #{price}, #{rights}, #{joint}, #{lease}, #{requirement}, #{furniture})")
    int insertAInfo(Info info);

    @Update("update info set phone='#{phone}', floor=#{floor}, picture=#{picture}, type=#{type}, area=#{area}, elevator=#{elevator}, decoration=#{decoration}," +
            " date=#{date}, location=#{location}, other=#{other}, orientation=#{orientation}, price=#{price}, rights=#{rights}, joint=#{joint}," +
            " lease=#{lease}, requirement=#{requirement}, furniture=#{furniture}" + " where id=#{id}")
    int updateAInfo(Info info);


    @Insert("insert into report(info_id, content, date) values (#{info_id}, #{content}, #{date})")
    int insertAReport(Report report);

    //匹配title
    @Select("select * from info where title like '%${title}%'")
    List<Info> matchTitle(String title);

    @Select("select username from info where id=#{id}")
    String findUserByInfoid(int id);
}